package com.lz.service.smsmail;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lz.rabbitmq.RabbitMqUtil;
import com.lz.rabbitmq.common.RabbitMqConstants;
import com.lz.rabbitmq.routing.LzRabbitMqRouteProducer;
import com.lz.service.smsmail.common.Config;
import com.lz.zookeeper.ZooKeeperClient;
import com.lz.zookeeper.ZooKeeperUtil;

/**
 * 应用初始化及销毁
 * @author likejian
 *
 */
public class Init{

	private final static Logger LOG = LoggerFactory.getLogger(Init.class); 
	
	//获取zk实例
	private final static ZooKeeperClient ZOOKEEPERCLIENT = ZooKeeperClient.getInstance(Config.ZK_SERVER_PATH, Config.ZK_CONFIG_PATH, Config.class);
	public static LzRabbitMqRouteProducer rabbitMqLogProducer =  null;
	
	public static void init() throws Exception{
		LOG.debug("======================" + Init.class +" init()========================");
		ZooKeeperUtil.startupZk(ZOOKEEPERCLIENT, "");
		RabbitMqUtil.init();
		if(rabbitMqLogProducer == null){
    		try {
    			rabbitMqLogProducer = new LzRabbitMqRouteProducer(RabbitMqUtil.connection,
						RabbitMqConstants.EXCHANGE_LZMH_LOG_ALL);
    			LOG.info("new LzRabbitMqRouteProducer"); 
			} catch (Exception e) {
				e.printStackTrace();
			}
    	}
	}

	public static void destroy() throws Exception {
		LOG.debug("======================" + Init.class +" destroy()========================");
		ZooKeeperUtil.shutdownZk(ZOOKEEPERCLIENT);
	}
}
